<?php
/**
 * 画像にウォーターマークを付ける関数
 * 要ASIDO
 *
 */
if(!function_exists('fWatermark')){
    function fWatermark($sSourcePath,$sWatermarkPath,$sSavePath,$iPos=4,$iWidth=0,$iHeight=0,$iRotate=0){
        /**
        * Include the main Asido class
        */
        require('ASIDO/class.asido.php');

        /**
        * Set the correct driver: this depends on your local environment
        */
        asido::driver('gd');

        /**
        * Create an Asido_Image object and provide the name of the source
        * image, and the name with which you want to save the file
        */
        $i1 = asido::image($sSourcePath, $sSavePath);

        /**
        * Put a watermark image on every possible gravity location
        */
        $watermark = $sWatermarkPath;

        switch($iPos){
            case 0:
                $iPos = ASIDO_WATERMARK_TOP_LEFT;
                break;
            case 1:
                $iPos = ASIDO_WATERMARK_TOP_CENTER;
                break;
            case 2:
                $iPos = ASIDO_WATERMARK_TOP_RIGHT;
                break;
            case 3:
                $iPos = ASIDO_WATERMARK_MIDDLE_RIGHT;
                break;
            case 4:
                $iPos = ASIDO_WATERMARK_BOTTOM_RIGHT;
                break;
            case 5:
                $iPos = ASIDO_WATERMARK_BOTTOM_CENTER;
                break;
            case 6:
                $iPos = ASIDO_WATERMARK_BOTTOM_LEFT;
                break;
            case 7:
                $iPos = ASIDO_WATERMARK_MIDDLE_LEFT;
                break;
            case 8:
                $iPos = ASIDO_WATERMARK_MIDDLE_CENTER;
                break;
            default:
                $iPos = ASIDO_WATERMARK_BOTTOM_RIGHT;
                break;
        }


        asido::watermark($i1, $watermark, $iPos,ASIDO_WATERMARK_SCALABLE_DISABLED);

        if(!Empty($iWidth) or !Empty($iHeight)){
            asido::resize($i1, $iWidth, $iHeight, ASIDO_RESIZE_STRETCH);
        }

        if(!Empty($iRotate)){
            asido::Rotate($i1,$iRotate);
        }

        /**
        * Save the result
        */
        if(File_Exists($sSavePath)) unlink($sSavePath);
        
        $i1->save(ASIDO_OVERWRITE_ENABLED);

        return(file_exists($sSavePath));

    }
}

?>